package com.lx.video.biz.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lx.bilibili.entity.VideoPlayHistory;
import com.lx.video.biz.IVideoplayhistroyService;
import com.lx.video.dao.VideoplayhistroyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lx
 * @since 2025-04-06
 */
@Service
public class VideoplayhistroyServiceImpl extends ServiceImpl<VideoplayhistroyMapper, VideoPlayHistory> implements IVideoplayhistroyService {

    @Autowired
    VideoplayhistroyMapper videoplayhistroyMapper;

    public int saveVideoProgress(VideoPlayHistory videoplayhistroy){
        LambdaQueryWrapper<VideoPlayHistory> lqw = new LambdaQueryWrapper<>();
        lqw.eq(VideoPlayHistory::getUid, videoplayhistroy.getUid());
        lqw.eq(VideoPlayHistory::getVid, videoplayhistroy.getVid());
        VideoPlayHistory IsExist = videoplayhistroyMapper.selectOne(lqw);
        if(IsExist!=null){
            IsExist.setEndtime(videoplayhistroy.getEndtime());
            IsExist.setTime(videoplayhistroy.getTime());
            return videoplayhistroyMapper.updateById(IsExist);
        }else{
            return videoplayhistroyMapper.insert(videoplayhistroy);
        }
    }
}
